package com.dd.cloud.common.vo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.cloud.common.constants.ZekeConstants;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
 * @author zk
 */
@Data
public class PageReq {
    /**
     * 页数
     */
    @NotNull(message = "页数不能为空")
    private Integer page;

    /**
     * 页数量
     */
    @NotNull(message = "页数量不能为空")
    private Integer pageSize;

    /**
     * @param searchCount 是否在执行前执行count语句
     * @param <T>         泛型
     * @return Page实体类
     */
    public <T> Page<T> pagePojo(boolean searchCount) {
        Page<T> page = pagePojo();
        return page.setSearchCount(searchCount);
    }

    public <T> Page<T> pagePojo() {
        if (this.pageSize > ZekeConstants.MAX_PAGESIZE){
            this.pageSize = ZekeConstants.MAX_PAGESIZE;
        }
        return new Page<>(this.page, this.pageSize);
    }

    public <T> PageVo<T> pageVoPojo() {
        return new PageVo<>(this.page, this.pageSize);
    }
}
